// pages/deatil-song/index.js
import store from '../../store/index'
import { getSongListDetail } from "../../service/api";
import {audioStore} from '../../store/audioctx'
Page({
  /**
   * 页面的初始数据
   */
  data: {
    infoObj: {},
    type: '',
    name: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({type: options.type})
    if (options.type == 'ranks') {
      this.setData({name: options.name})
      store.onState(options.name, this.getData)
    } else {
      getSongListDetail(options.id).then(e => {
        const {playlist} =e
        this.setData({infoObj: playlist})
      })
    }
  },
  getData(res) {
    this.setData({infoObj: res})
  },
  musicItemTap(e) {
    audioStore.setState('songsPlayList', this.data.infoObj.tracks)
    audioStore.setState('currentPlayIndex', e.currentTarget.dataset.index)
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    if (this.data.type == 'ranks') {
      store.offState(this.data.name, this.getData)
    }
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})